package com.chucang.shucang.bac.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chucang.shucang.bac.entity.AppSwiperEntity;
import com.chucang.shucang.bac.service.AppSwiperService;
import com.chucang.shucang.bac.vo.AppSwiperResVO;
import com.chucang.shucang.common.base.utils.R;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;


/**
 * app首页轮播图配置
 *
 * @author flitsneak flitsneak@gmail.com
 * @since 1.0.0 2022-09-11
 */
@RestController
@RequestMapping("/appswiper")
@RequiredArgsConstructor
@Api(tags = "app首页轮播图配置")
public class AppSwiperController {

    private final AppSwiperService appSwiperService;

    @GetMapping("/listSwiper")
    public R<List<AppSwiperResVO>> listSwiper() {
        LambdaQueryWrapper<AppSwiperEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .lt(AppSwiperEntity::getEndTime, new Date())
                .orderByDesc(AppSwiperEntity::getStartTime)
                .orderByAsc(AppSwiperEntity::getSortId);
        List<AppSwiperEntity> list = appSwiperService.list(lambdaQueryWrapper);
        List<AppSwiperResVO> appSwiperResVOS = BeanUtil.copyToList(list, AppSwiperResVO.class);
        return R.ok(appSwiperResVOS);
    }
}